<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>节流</title>
    <script src="./js/lodash.js"></script>
  </head>
  <body>
    <div>
      <h1>我是计数器<span>0</span></h1>
      <button>点击我加1</button>
    </div>
    <script>
      // 节流：在规定的间隔时间范围内不会重复触发回调，只有大于这个时间间隔才会触发回调，把频繁触发变为少量触发
      let span = document.querySelector('span')
      let btn = document.querySelector('button')
      let count = 0
      btn.onclick = _.throttle(function () {
        count++
        span.innerHTML = count
      }, 1000)
    </script>
  </body>
</html>
